/**
 * @param {string} s1
 * @param {string} s2
 * @param {string} s3
 * @return {boolean}
 */
var isInterleave = function (s1, s2, s3) {
  if (s1.length + s2.length !== s3.length) {
    return false
  }
  if (s3.length === 0) {
    return true
  }
  let i = s3.length
  let flag = false
  const hasData = (word, targetWord1, targetWord2, index) => {
    if (index === i && targetWord1.length === 0 && targetWord2.length === 0) {
      flag = true
      return flag
    }
    if (word.charAt(index) === targetWord1.charAt(0)) {
      hasData(word, targetWord1.slice(1), targetWord2, index + 1)
    }
    if (word.charAt(index) === targetWord2.charAt(0)) {
      hasData(word, targetWord1, targetWord2.slice(1), index + 1)
    }
  }
  hasData(s3, s1, s2, 0)
  return flag
}
console.log(isInterleave('aabcc', 'dbbca', 'aadbbcbcac'))
